package br.com.util;

import java.util.List;    

import br.com.domain.Domain;
    
      
@SuppressWarnings({"serial","unchecked" })  
public class DomainListDataModel extends PrimeDataModel<Domain> {  
      
   public DomainListDataModel() {  
   }  
 
   public DomainListDataModel(Object data) {  
       super(data);  
   }  
     
   @Override  
   public Domain getRowData(String rowKey) {    
    
	List<Domain> listDomain = (List<Domain>) getWrappedData();  
         
       for(Domain domain : listDomain) {  
           String id = ""+domain.getId();  
           if(id.equals(rowKey))  
               return domain;  
       }  
         
       return null;  
   }  
 
   @Override  
   public String getRowKey(Domain domain) {  
      return ""+domain.getId();  
   }
   
   public void add(Domain domain) {  
	   List<Domain> listDomain = (List<Domain>) getWrappedData();  
	   listDomain.add(domain);
      
   }
   
   public void add(Domain domain, Integer index) {  
	   List<Domain> listDomain = (List<Domain>) getWrappedData();  
	   listDomain.add(index, domain);
      
   }
   
   public void remove(Domain domain) {  
	   List<Domain> listDomain = (List<Domain>) getWrappedData();  
	   listDomain.remove(domain);
      
   }
   
   public int size() {  
	   int retorno = 0;
	   List<Domain> listDomain = (List<Domain>) getWrappedData();  
	   retorno = listDomain == null ? 0 : listDomain.size();
	   return retorno;
   }
   
   public List<Domain> getListDomain() {  
	   List<Domain> listDomain = (List<Domain>) getWrappedData();  
	   return listDomain;  
      
   }
   
   public Integer getIndex(Domain domain) {  
	   List<Domain> listDomain = (List<Domain>) getWrappedData();  
	  
	   int index = 0;
	   for (Domain domainFor : listDomain) {
		   if (domainFor.getId().equals(domain.getId())) {
			   break;			  
		   }
		   index++;
	   }
       return index;   
   }
   
   
   
   
 }  